import RootSiblings from 'react-native-root-siblings'

let elements = [];

export default class Popup {

    static show(view) {
        const sibling = new RootSiblings(view);
        const newLength = elements.push(sibling);
        return newLength - 1;
    }

    static update(index, view) {
        index >= 0 && elements[index].update(view);
    }

    static destroy() {
        const siblings = elements.pop();
        siblings && siblings.destroy();
    }

    static destroyAllSibling = () => {
        const len = elements.length;
        if (len > 0) {
            for (let i = 0; i < len; i++) {
                if (elements[i]) {
                    elements[i].destroy();
                }
            }
        }
    };
}
